import { message } from "ant-design-vue"
import { uploadPhoto } from "@/api/multidimensionalAnalysis"

/**
 * 上传图片
 * @param { File } file 文件对象
 * @param { string } fieldName 字段名
 * @param { object} form
 * @returns { Promise<string> }
 */
 export function uploadImg(file, fieldName, form) {
  return new Promise((resolve, reject)=> {
    form[`${fieldName}loading`] = true
    const formData = new FormData()
    formData.append("file", file)
    uploadPhoto(formData)
    .then(data => {
      form[`${fieldName}loading`] = false
      if(data.errorCode === 0){
        resolve(data.data)
      }
      else {
        message.error(data.msg)
        reject()
      }


    })
  })

}
